/*
 * Copyright (c) 2010 MoSync AB
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef MAINTERPETER_SYSTEM_H
#define MAINTERPETER_SYSTEM_H

#include <ma.h>
#include <MAUtil/HashMap.h>
#include <MAUI/Font.h>

namespace MAInterpreter
{

/**
 * This class provides system services.
 */
class System
{
public:
	static System* instance();
	static void releaseInstance();
	System();
	virtual ~System();
	int getScreenWidth();
	int getScreenHeight();

	/**
	 * This is how you bind font names:
	 *  Sys()->addFont("Arial20BoldBlack", new Font(ARIAL20BOLDBLACK));
	 *  Sys()->addFont("Arial32BoldBlack", new Font(ARIAL32BOLDBLACK));
	 *  Sys()->addFont("Arial20BoldWhite", new Font(ARIAL20BOLDWHITE));
	 *  Sys()->addFont("Arial32BoldWhite", new Font(ARIAL32BOLDBWHITE));
	 *
	 * Then in Lua, you can call:
	 *  Screen.drawText("Hello World", 10, 10, "Arial32BoldWhite")
	 */
	void addFont(const char* fontName, MAHandle fontData);

	MAUI::Font* getFont(const char* fontName);
	void freeFontTable();
	static char* loadTextResource(MAHandle data);
	static wchar* charToWideCharString(const char* str);
	static char* wideCharToCharString(const wchar* wstr);
	static int writeStringToStore(const char* storeName, const char* data);
	static char* readStringFromStore(const char* storeName);

public:
	static System* _instance;
	MAUtil::HashMap<MAUtil::String, MAUI::Font*> fonts;
};

/**
 * Function that returns the system instance.
 */
System* Sys();

}

#endif
